package com.example.yc23.demo.controller.fore;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.yc23.demo.pojo.Review;
import com.example.yc23.demo.service.ReviewService;
import com.example.yc23.demo.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/fore/review")
public class ForeReviewController {
    @Autowired
    private ReviewService reviewService;
    @RequestMapping("/thumbsup")
    public JsonResult thumbsup(Integer reviewId, String token){
        return reviewService.thumbsUp(reviewId,token);
    }
    @RequestMapping("/detail")
    public Review detail(Integer id){
        return reviewService.getById(id);
    }

    //按照评论时间对评论进行排序并返回
    @RequestMapping("/listOrder2")
    public List<Review> listOrder2(){
        return reviewService.orderByTime();
    }
    //按照点赞次数对评论进行排序并返回
    @RequestMapping("/listOrder")
    public List<Review> listOrder(){
        return reviewService.orderByThumbsup();
    }

    /**
     * 根据电影Id查看评论列表
     * @param pn    当前页
     * @param ps    每页PS条评论
     * @param filmId 电影ID
     * @return
     */
    @GetMapping("/list")
    public Page<Review> list(@RequestParam(defaultValue = "1") Integer pn,
                             @RequestParam(defaultValue = "5") Integer ps,Integer filmId){
        QueryWrapper wrapper=null;
        wrapper=new QueryWrapper();
        wrapper.eq("state",1);
        if (filmId!=null){
            wrapper.eq("film_id",filmId);
        }
        return reviewService.page(new Page<>(pn,ps),wrapper);
    }




}


